﻿using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WINBASE
{
    public partial class frmRmrp : Form
    {
        string RptSrvName;
        string RptFileName;

        public frmRmrp(string ReportFileName)
        {
            InitializeComponent();
            this.RptSrvName = ApplicationData.DtAppSetting.Rows[0]["ReportServerName"].ToString();
            this.RptFileName = ReportFileName;
            this.Size = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
            this.Location = new Point(0, 0);
        }

        private void frmRmrp_Load(object sender, EventArgs e)
        {
            InitializeReport(RptSrvName,RptFileName);
        }

        public void InitializeReport(string ReportServerName,string ReportFileName)
        {
            this.reportViewer1.Reset();
            this.reportViewer1.ProcessingMode = ProcessingMode.Remote;
            this.reportViewer1.ServerReport.ReportServerUrl = new Uri(ReportServerName);
            this.reportViewer1.ServerReport.ReportPath = "/" + ReportFileName;
            this.reportViewer1.ServerReport.SetParameters(new ReportParameter("UserName",ApplicationData.UserId));

            PageSettings pg = new PageSettings();
            pg.Margins.Top = 30;
            pg.Margins.Bottom = 30;
            pg.Margins.Left = 30;
            pg.Margins.Right = 30;
            System.Drawing.Printing.PaperSize size = new PaperSize();
            size.RawKind = (int)PaperKind.A4;
            pg.PaperSize = size;
            reportViewer1.SetPageSettings(pg);
            reportViewer1.ZoomMode = ZoomMode.Percent;
            reportViewer1.ZoomPercent = 100;
            this.reportViewer1.RefreshReport();
        }
    }
}